{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "364bbf7f-dfa3-46ed-9220-313b99102eef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "str()默认情况下为： \n",
      "float 字符型转换为 str： 232.33\n",
      "int 浮点型转换为 str： 32\n",
      "列表 list 转换为 str: abecda\n",
      "序列 strs 转换为 list: ['h', 'o', 'n', 'g', 't', 'e', 'n']\n",
      "列表 list 转换为 tuple: ('a', 'b', 'e', 'c', 'd', 'a')\n",
      "整数转换为字符 chr: C\n",
      "字符 chr 转换为整数: 67\n",
      "整数转 16 进制数: 0xc\n",
      "整数转 8 进制数: 0o14\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\" 类型转换 \"\"\"\n",
    "\"\"\" \n",
    "int(x [,base]) 将 x 转换为一个整数\n",
    "long(x [,base] ) 将 x 转换为一个长整数\n",
    "float(x) 将 x 转换到一个浮点数\n",
    "complex(real[,imag]) 创建一个复数\n",
    "str(x) 将对象 x 转换为字符串\n",
    "repr(x) 将对象 x 转换为表达式字符串\n",
    "val(str) 用来计算在字符串中的有效 Python 表达式,并返回一个对象\n",
    "Complex(A) 将参数转换为复数型\n",
    "tuple(s) 将序列 s 转换为一个元组\n",
    "list(s) 将序列 s 转换为一个列表\n",
    "set(s) 转换为可变集合\n",
    "dict(d) 创建一个字典。d 必须是一个序列 (key,value)元组\n",
    "frozenset(s) 转换为不可变集合\n",
    "chr(x) 将一个整数转换为一个字符\n",
    "unichr(x) 将一个整数转换为 Unicode 字符\n",
    "ord(x) 将一个字符转换为它的整数值\n",
    "hex(x) 将一个整数转换为一个十六进制字符串\n",
    "oct(x) 将一个整数转换为一个八进制字符串\n",
    "\"\"\"\n",
    "\n",
    "# 转换为 str 字符串\n",
    "print('str()默认情况下为：', str()) # str()默认情况下为： \n",
    "print('float 字符型转换为 str：', str(232.33)) # float 字符型转换为 str： 232.33\n",
    "print('int 浮点型转换为 str：', str(32)) # int 浮点型转换为 str： 32\n",
    "lists = ['a', 'b', 'e', 'c', 'd', 'a']\n",
    "print('列表 list 转换为 str:', ''.join(lists)) # 列表 list 转换为 str: abecda\n",
    "\n",
    "#转换为 list\n",
    "strs = 'hongten' \n",
    "print('序列 strs 转换为 list:', list(strs)) # 序列 strs 转换为 list: ['h', 'o', 'n', 'g', 't', 'e', 'n']\n",
    "#转换为 tuple\n",
    "print('列表 list 转换为 tuple:', tuple(lists)) # 列表 list 转换为 tuple: ('a', 'b', 'e', 'c', 'd', 'a')\n",
    "#字符和整数之间的转换\n",
    "print('整数转换为字符 chr:', chr(67)) # 整数转换为字符 chr: C\n",
    "print('字符 chr 转换为整数:', ord('C')) # 字符 chr 转换为整数: 67\n",
    "print('整数转 16 进制数:', hex(12)) # 整数转 16 进制数: 0xc\n",
    "print('整数转 8 进制数:', oct(12)) # 整数转 8 进制数: 0o14\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2a267329-07dd-4c63-920c-f6fbdb1a131e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 判断变量类型\n",
    "print(isinstance('str', str)) # True\n",
    "print(isinstance(True, str)) # False\n",
    "print(isinstance(True, bool)) # True"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
